package com.yycx.module.bus.provider.handler.invoice;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.DeleteInterceptor;
import com.yycx.common.mybatis.query.CriteriaDelete;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.provider.service.BusOrderDetailsService;
import com.yycx.module.bus.provider.service.BusPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 开票税金删除扩展
 *
 * @author zyf
 */
@Component("invoicePaymentDeleteHandler")
public class InvoicePaymentDeleteHandler implements DeleteInterceptor {

    @Autowired
    private BusOrderDetailsService orderDetailsService;
    @Autowired
    private BusPaymentService paymentService;

    @Override
    public void prepare(CriteriaDelete criteriaDelete, EntityMap entityMap) {
        BusPayment payment = paymentService.getById(criteriaDelete.getIdValue());
        Integer settleType = FlymeUtils.getInteger(payment.getSettleType(), 1);
        entityMap.put("settleType",settleType);
    }

    @Override
    public void complete(CriteriaDelete cq, EntityMap params) {
        Integer settleType=params.getInt("settleType",1);
        orderDetailsService.clearInvoiceInfo(cq.getIdValue(),settleType);
    }
}
